package cn.edu.fzu.homemaking.company.util;

import java.util.Objects;

import javax.servlet.http.HttpServletRequest;

import cn.edu.fzu.homemaking.common.SessionConstant;
import cn.edu.fzu.homemaking.company.domain.entity.CompanyUser;
import cn.edu.fzu.homemaking.exception.ServiceException;

public class UserInfoUtil {

    public static CompanyUser getUserInfo(HttpServletRequest request, boolean allowNull) {
        if (Objects.equals(SessionConstant.COMPANY, request.getSession().getAttribute(SessionConstant.USER_TYPE))) {
            return (CompanyUser) request.getSession().getAttribute(SessionConstant.ACCOUNT);
        }
        if (!allowNull) {
            throw new ServiceException("非法访问");
        }
        return null;
    }
}
